Passed
Push — master ( 06bde6...6d2f62 )
by Paul
04:59
created

Status.onClick_   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
1
/** global: GLSR, jQuery */
2
;(function( x ) {
3
4
	'use strict';
5
6
	var Status = function( selector ) {
7
		var elements = document.querySelectorAll( selector );
8
		if( !elements.length )return;
9
		elements.forEach( function( el ) {
10
			el.addEventListener( 'click', this.onClick_ );
11
		}.bind( this ));
12
	};
13
14
	Status.prototype = {
15
		/** @return void */
16
		onClick_: function( ev ) { // MouseEvent
17
			var post_id = ev.target.href.match( /post=([0-9]+)/ );
18
			var status = ev.target.href.match( /action=([a-z]+)/ );
19
			if( post_id === null || status === null )return;
20
			var request = {
21
				action: 'change-review-status',
22
				nonce: GLSR.nonce['change-review-status'],
23
				post_id: post_id[1],
24
				status: status[1],
25
			};
26
			(new GLSR.Ajax( request, ev )).post( function( response ) {
27
				if( !response.class )return;
28
				var el = x( ev.target );
29
				el.closest( 'tr' ).removeClass( 'status-pending status-publish' ).addClass( response.class );
30
				el.closest( 'td.column-title' ).find( 'strong' ).html( response.link );
31
			});
32
		},
33
	};
34
35
	GLSR.Status = Status;
36
})( jQuery );
37